package sw6.bmi.profile;

import java.io.ByteArrayOutputStream;
import java.io.Serializable;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;

public class Image implements Serializable {

	private static final long serialVersionUID = 1L;
	
	private byte[] mImageData;
	
	public Image(Bitmap bitmap) {
		setImage(bitmap);
	}
	
	public Bitmap getImageBitmap() {
		BitmapFactory.Options options=new BitmapFactory.Options();
		options.inSampleSize = 4;
		return BitmapFactory.decodeByteArray(mImageData, 0, mImageData.length, options);
	}
	
	private void setImage(Bitmap bitmap) {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		bitmap.compress(CompressFormat.JPEG, 90, baos);
		mImageData = baos.toByteArray();
	}
}
